package com.meng.love;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

public class MainActivity extends AppCompatActivity {
    EditText editTextHtml;
    EditText editTextTitle;
    EditText editTextMessage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editTextHtml = (EditText) findViewById(R.id.et_html);
        editTextTitle = (EditText) findViewById(R.id.et_title);
        editTextMessage = (EditText) findViewById(R.id.et_message);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                String hongbao = "https://h5.ele.me/presenthongbao/#sn=20170614004418063225552869774&id=2371945&user_id=18063225&sig=847b941326321df54c598679cd6c593594d6b44b&type=weixin";
                String hongbao = editTextHtml.getText().toString();
                UMWeb web = new UMWeb(hongbao);
                web.setTitle(editTextTitle.getText().toString());
                web.setThumb(new UMImage(MainActivity.this, R.mipmap.xm));
                web.setDescription(editTextMessage.getText().toString());
                new ShareAction(MainActivity.this)
                .setPlatform(SHARE_MEDIA.WEIXIN)
                .withText("text")
                .withMedia(web).share();
            }
        });
    }
//    IWXAPI api;
//    private void fun(){
//        api = WXAPIFactory.createWXAPI(this,"");
//        WXWebpageObject webpage = new WXWebpageObject();
//        webpage.webpageUrl = "http://www.mengmeng1314521.com";
//        WXMediaMessage msg = new WXMediaMessage(webpage);
//        msg.title = "萌萌呀";
//        msg.description = "描述！！";
//        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.umeng_socialize_back_icon);
//        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 150, 150, true);
//        bmp.recycle();
//        msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
//
//        SendMessageToWX.Req req = new SendMessageToWX.Req();
//        req.transaction = buildTransaction("webpage");
//        req.message = msg;
//        req.scene = SendMessageToWX.Req.WXSceneSession;
//        api.sendReq(req);
//    }
    private String buildTransaction(final String type) {
        return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
    }
}
